All Questions
20 questions
-1votes
1answer
70views
why are numpy arrays printed like this?
Take for example generating random a 7x5x3 RGB image. import numpy as np import matplotlib.pyplot as plt # Create a random 7x5x3 RGB image image = np.random.randint(0, 256, size=(7, 5, 3), dtype=np....
1vote
1answer
158views
How can I count the number of boxes in a PNG image using Numpy and avoid nested loops?
I want to be more efficient with my code. I have a PNG and I want to cut the image in boxes. The goal is to count the number of boxes where I have at least one none black pixel. I have only one ...
0votes
2answers
190views
Unable to save an image after an array
I got this Error : Traceback (most recent call last): File "/home/runner/Image-Loader/venv/lib/python3.8/site-packages/PIL/Image.py", line 2992, in fromarray mode, rawmode = ...
0votes
0answers
60views
Import an image as a 2D array of RGB tuples rather than a 3D array of values [duplicate]
Is there a NumPy function or "way" to directly import an image as a 2D array of RGB 3-tuples instead of the usual 3D array of values? So far, I've arrived at this solution: from PIL import ...
1vote
2answers
486views
Show a 2d numpy array where contents are tuples as an image
I have a 2d (M * N) numpy array, where each cell contains a tuple of length 3. The tuple contains R, G, and B values for each pixel, e.g. A[0,0] = (0, 255, 0) Is there a way to show this array as an ...
1vote
3answers
628views
How to turn 3d array into 2d array with labels based on the 3rd dimension? [duplicate]
I have a 3D NumPy Array with dimensions (224, 224, 3). The third dimension represents colors. I have only 21 colors in the whole picture so there are only 21 distinct values for each pixel. These are ...
0votes
1answer
258views
How to convert numpy array into image using PIL?
The following code gives me black images and I can't understand why: Imports: import numpy as np from PIL import Image Code: arr2 = np.zeros((200,200), dtype=int) arr2[80:120,80:120]=1 im = Image....
0votes
1answer
1kviews
How to make 4 channel image by extracting 4 channels from different color space?
I have extracted four channels from different color spaces and then want to combine the h,s, cb and cr channels. For this, I have converted them into a list and then appended them all one by one. ...
0votes
1answer
75views
Save Numpy array graphs and images as images
I cannot find a way to save my graphs and images. I have tried from from PIL import Image im = Image.fromarray() im.save("your_file.jpeg") but doesn't work!
6votes
1answer
19kviews
PIL TypeError: Cannot handle this data type: (1, 1, 1), |u1
I have a numpy.ndarray of shape (1,28,28) and values are floating point in range [0,1]. My ultimate goal is to save the array as a png image. Even after transposing the array and multiplying it with ...
0votes
1answer
1kviews
Import images to Numpy array, then divide into training and test sets
I have a set of 20,000 images that I am importing from disk like below. imgs_dict={} path="Documents/data/img" os.listdir(path) valid_images =[".png"] for f in os.listdir(path): ext= os.path....
0votes
1answer
347views
Create 1-D numpy array from image
edit: copying from my comment to give more context to the problem One important thing I forgot to mention is my end goal is to add this as a column to a pandas dataframe. I was getting errors when ...
2votes
2answers
1kviews
Replace certain pixels by integers in numpy array
I have made myself a numpy array from a picture using from PIL import Image import numpy as np image = Image.open(file) np.array(image) its shape is (6000, 6000, 4) and in that array I would like to ...
-1votes
1answer
836views
How can I change the shape of this numpy array to (3058, 480, 640, 3)?
I am trying to read 3058 images from a folder. I want my picture to be read as np array with size (3158, 480, 640, 3) dtype as uint8. I store all image to a list (image_list). After changing the list ...
2votes
1answer
2kviews
AssertionError: HybridBlock requires the first argument to forward be either Symbol or NDArray, but got <class 'numpy.ndarray'>
I'm trying to run a pre-made program on my image, and the image type is a numpy array. When I hit enter, I get this error: AssertionError: HybridBlock requires the first argument to forward be ...